package com.z2k.jdbc.service;

import com.z2k.jdbc.entity.Student;
import com.z2k.jdbc.reflect.ResultSetToBean;
import com.z2k.jdbc.util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;

public class Query {
    public void query(){
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;

        conn = DBUtil.getConnection();
        String sql = "select id,name,score from student";
        try {
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            Student stu = new Student();
            while(rs.next()){
                List<Student> list = ResultSetToBean.rstobean(rs, Class.forName("com.z2k.jdbc.entity.Student"));
                for (Student t : list) {
                    System.out.println("学号：" + t.getId() + "  姓名：" + t.getName() + "  成绩：" + t.getScore());
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
